<?php
namespace App\Http\Controllers\Api\Mall;

use App\Http\Controllers\Controller;
use App\Models\Mall\GoodsType;
use App\UserCoinLog;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;

class IndexController extends Controller 
{
	public function index( Request $request )
	{
		$banner = [
			['img' => 'http://xy-cdn.oss-cn-hangzhou.aliyuncs.com/xywy/lunbo3.jpg', 'url' => '/zghpt/vip/page'],
			['img' => 'http://xy-cdn.oss-cn-hangzhou.aliyuncs.com/xywy/lunbo4.jpg', 'url' => '/ant/notice'],
            ['img' => 'http://xy-cdn.oss-cn-hangzhou.aliyuncs.com/xywy/lunbo2.jpg', 'url' => '/wolf'],
		];

		$data['banner'] = $banner;
		$data['types']  = GoodsType::get();

		return response()->json( ['code' => 1000, 'msg' => 'ok', 'data' => $data] )->withCallback($request->input('callback'));
	}

	//首页轮播
	public function carousel( Request $request )
	{
        $datas = Cache::remember('mall_index_carousel', 1, function () {
            $logs = UserCoinLog::where('bussiness_id', '>', 0)
                ->where('type', 1)
                ->where('coin', '>', 0)
                ->orderBy('id', 'desc')
                ->take(100)
                ->get();

            $datas = [];
            foreach ($logs as $log) {
                $datas[] = [
                    'nickname' => $log->user->nickname,
                    'description' => $log->desc,
                    'coin'		=> $log->coin
                ];
            }
            return $datas;
        });

		return response()->json(['code' => 1000, 'data' => $datas])->withCallback($request->input('callback'));
	}

	public function game()
    {
        $data = [];

        $data['games'] = [
            ['name' => '欢乐钓鱼', 'icon' => '/ananas/img/page/gameicon/game_diaoyu.png', 'url' => '/hldy2/page'],
            ['name' => '欢乐攻城', 'icon' => '/ananas/img/page/gameicon/game_gongcheng.png', 'url' => '/hlgc/page'],
            ['name' => '水果达人', 'icon' => '/ananas/img/page/gameicon/game_shuiguo.png', 'url' => '/sgdzz/page'],
            ['name' => '趣味猜拳', 'icon' => '/ananas/img/page/gameicon/game_qwcq.png', 'url' => '/cq/page'],
        ];

        return response()->json(['code' => 1000, 'data' => $data]);
    }

    public function foot()
    {
        $data = [];

        $data['foots'] = [
            ['name' => '广场', 'icon' => '/app/tabbar_square@2x.png', 'url' => '/mall'],
            ['name' => '聚宝盆', 'icon' => '/app/tabbar_jbp@2x.png', 'url' => '/jbp/page'],
            ['name' => '我的', 'icon' => '/app/tabbar_mine@2x.png', 'url' => '/user/usercenter'],
        ];

        return response()->json(['code' => 1000, 'data' => $data]);
    }
}